//年
var year = 2019;
//月
var mounth = 5;

document.querySelector("#nian").innerHTML = year;
document.querySelector("#yue").innerHTML = mounth;

//判断这一年是不是闰年
function runNian(y) {
	if (y % 400 === 0 || (y % 4 === 0 && y % 100 !== 0)) {
		return true;
	} else {
		return false;
	}
}
//总天数
var days = 0;
for (var i = 1980; i < year; i++) {
	if (runNian(i)) {
		days += 366;
	} else {
		days += 365;
	}
}


//2019 一月到， 本月上个月的总天数

for (var k = 1; k < mounth; k++) {
	switch (k) {
		case 1:
			days += 31;
			break;
		case 2:
			if (runNian(year)) {
				days += 29;
			} else {
				days += 28;
			}
			break;
		case 3:
			days += 31;
			break;
		case 4:
			days += 30;
			break;
		case 5:
			days += 31;
			break;
		case 6:
			days += 30;
			break;
		case 7:
			days += 31;
			break;
		case 8:
			days += 31;
			break;
		case 9:
			days += 30;
			break;
		case 10:
			days += 31;
			break;
		case 11:
			days += 30;
			break;
		case 12:
			days += 31;
			break;
	}
}



//本月多少天
var dayes = 0;
switch (mounth) {
	case 1:
		dayes += 31;
		break;
	case 2:
		if (runNian(year)) {
			dayes += 29;
		} else {
			dayes += 28;
		}
		break;
	case 3:
		dayes += 31;
		break;
	case 4:
		dayes += 30;
		break;
	case 5:
		dayes += 31;
		break;
	case 6:
		dayes += 30;
		break;
	case 7:
		dayes += 31;
		break;
	case 8:
		dayes += 31;
		break;
	case 9:
		dayes += 30;
		break;
	case 10:
		dayes += 31;
		break;
	case 11:
		dayes += 30;
		break;
	case 12:
		dayes += 31;
		break;
}
console.log(dayes)


//上个月一共多少天
var prevDay = 0;
switch (mounth - 1) {
	case 1:
		prevDay += 31;
		break;
	case 2:
		if (runNian(year)) {
			prevDay += 29;
		} else {
			prevDay += 28;
		}
		break;
	case 3:
		prevDay += 31;
		break;
	case 4:
		prevDay += 30;
		break;
	case 5:
		prevDay += 31;
		break;
	case 6:
		prevDay += 30;
		break;
	case 7:
		prevDay += 31;
		break;
	case 8:
		prevDay += 31;
		break;
	case 9:
		prevDay += 30;
		break;
	case 10:
		prevDay += 31;
		break;
	case 11:
		prevDay += 30;
		break;
	case 12:
		prevDay += 31;
		break;
}
console.log(prevDay)
// 总天数、
//1980一月一日从周二开始所以加2
days = days + 2;
console.log(days)
//本月一号在周几
var sa = days % 7;
console.log(sa)
//显示的下个月几天
var nextDays = 42 - sa - dayes;

//今天周几
var thisdate = new Date().getDate();

var date1 = document.querySelector("#date1");
//前边空的天数
for (var j = prevDay - sa + 1; j <= prevDay; j++) {
	date1.innerHTML += "<span class ='h'>" + j + "</span>";
}
//本月的天数
for (var a = 1; a <= dayes; a++) {
	if (a == thisdate) {
		date1.innerHTML += "<span class ='today'>" + a + "</span>";
	} else {
		date1.innerHTML += "<span>" + a + "</span>";
	}
}

//下边多余的天数
for (var s = 1; s <= nextDays; s++) {
	date1.innerHTML += "<span class ='h'>" + s + "</span>";
}

